/*
 * XPathMatchFilter.java
 *
 * Created on March 2, 2007, 2:15 PM
 *
 * (C) R. Alexander Milowski alex@milowski.com
 */

package com.smallx.xpath;

import org.infoset.xml.Item;
import org.infoset.xml.ItemDestination;
import org.infoset.xml.XMLException;
import org.infoset.xml.filter.ItemFilter;

/**
 *
 * @author R. Alexander Milowski
 */
public class XPathMatchFilter implements ItemFilter {

   ItemDestination output;
   XPathMatcher matcher;
   /** Creates a new instance of XPathMatchFilter */
   public XPathMatchFilter(XPathMatcher matcher) {
      this.matcher = matcher;
   }
   
   public void send(Item item)
      throws XMLException
   {
      if (item.getType()==Item.ItemType.DocumentItem) {
         matcher.reset();
      }
      Item match = matcher.match(item);
      if (match!=null && output!=null) {
         output.send(match);
      }
   }
   
   public void attach(ItemDestination dest) {
      this.output = dest;
   }
   
}
